package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.SysCompanyVo;
import com.ruoyi.system.domain.bo.SysCompanyBo;
import com.ruoyi.system.service.ISysCompanyService;

/**
 * 公司部门管理
 *
 * @author zyb
 * @date 2024-12-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/company")
public class SysCompanyController extends BaseController {

    private final ISysCompanyService iSysCompanyService;

    /**
     * 查询公司部门管理列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public R<List<SysCompanyVo>> list(SysCompanyBo bo) {
        List<SysCompanyVo> list = iSysCompanyService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出公司部门管理列表
     */
    @SaCheckLogin
    @Log(title = "公司部门管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysCompanyBo bo, HttpServletResponse response) {
        List<SysCompanyVo> list = iSysCompanyService.queryList(bo);
        ExcelUtil.exportExcel(list, "公司部门管理", SysCompanyVo.class, response);
    }

    /**
     * 获取公司部门管理详细信息
     *
     * @param companyId 主键
     */
    @SaCheckLogin
    @GetMapping("/{companyId}")
    public R<SysCompanyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long companyId) {
        return R.ok(iSysCompanyService.queryById(companyId));
    }

    /**
     * 新增公司部门管理
     */
    @SaCheckLogin
    @Log(title = "公司部门管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysCompanyBo bo) {
        return toAjax(iSysCompanyService.insertByBo(bo));
    }

    /**
     * 修改公司部门管理
     */
    @SaCheckLogin
    @Log(title = "公司部门管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCompanyBo bo) {
        return toAjax(iSysCompanyService.updateByBo(bo));
    }

    /**
     * 删除公司部门管理
     *
     * @param companyIds 主键串
     */
    @SaCheckLogin
    @Log(title = "公司部门管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{companyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] companyIds) {
        return toAjax(iSysCompanyService.deleteWithValidByIds(Arrays.asList(companyIds), true));
    }
}
